package ts.group.webapp.market.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ts.group.webapp.market.dao.IDistributorDao;
import ts.group.webapp.market.model.TDistributor;

import com.starit.common.dao.support.Pagination;
import com.starit.common.dao.support.PaginationRequest;

@Service
public class IDistService {
	
	@Autowired
	private IDistributorDao IDistributorDao;
	
	/*根据id查询记录*/
	public TDistributor  getDistributorById( Long id){
		return IDistributorDao.get(id);
	}
	
	
	/*查询所有记录*/
	public Pagination<TDistributor>  findAllForPage(PaginationRequest paginationRequest){
		return IDistributorDao.findPage(paginationRequest);
	}
	
	/*根据编号查询经销商*/
	public List<TDistributor> getDistributorByCode(String distributorCode){
		if(distributorCode == null){
			return new ArrayList<TDistributor>(0);
		}
		return IDistributorDao.findByNamedParam("distributorCode", distributorCode);
	}
	
	/*新增经销商*/
	public Long createDistributor(TDistributor TDistributor){
		return IDistributorDao.save(TDistributor);
	}
	
	/*更新经销商*/
	public void updateDistributor(TDistributor TDistributor){
		IDistributorDao.update(TDistributor);
	}
	
	/*删除经销商*/
	public void removeDistributor(Long distId){
		IDistributorDao.delete(distId);
	}
	
	/*根据店铺Id，查询该店铺下的所有经销商*/
	public List<TDistributor> getDistributorByShopId(Long shopId){
		return IDistributorDao.findByNamedParam("shopId", shopId);
	}
}
